package com.zj.core.ui

import android.content.Context
import android.support.constraint.ConstraintLayout
import android.support.constraint.ConstraintLayout.LayoutParams.PARENT_ID
import android.view.View
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.constraint.layout.guideline
import org.jetbrains.anko.constraint.layout.matchConstraint

class LoginActivityUi(click: View.OnClickListener,longClick:View.OnLongClickListener): AnkoComponent<Context> {
    private val clickListaner=click
    private val longClickListaner=longClick

    override fun createView(ui: AnkoContext<Context>): View = with(ui) {
        constraintLayout {
            guideline {
                id = R.id.guideline_h_25
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent = 0.25F
            }

            guideline {
                id = R.id.guideline_h_40
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent = 0.4F
            }

            guideline {
                id = R.id.guideline_h_70
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent = 0.7F
            }

            guideline {
                id = R.id.guideline_h_85
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.HORIZONTAL
                guidePercent = 0.85F
            }

            guideline {
                id = R.id.guideline_v_20
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.VERTICAL
                guidePercent = 0.2F
            }

            guideline {
                id = R.id.guideline_v_25
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.VERTICAL
                guidePercent = 0.25F
            }

            guideline {
                id = R.id.guideline_v_75
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.VERTICAL
                guidePercent = 0.75F
            }

            guideline {
                id = R.id.guideline_v_80
            }.lparams(width = matchConstraint, height = matchConstraint) {
                orientation = ConstraintLayout.LayoutParams.VERTICAL
                guidePercent = 0.8F
            }

            imageView {
                id=R.id.login_logo_img
                imageResource = R.mipmap.logo
            }.lparams (0,0){
                topToBottom = R.id.guideline_h_25
                bottomToTop = R.id.guideline_h_40
                leftToRight = R.id.guideline_v_25
                rightToLeft = R.id.guideline_v_75
            }

            view{
                id=R.id.view_line
                backgroundColor=context.resources.getColor(R.color.colorsFrenchGrey)
            }.lparams(width = 0, height = dip(2)){
                setMargins(0,20,0,0)
                topToBottom = R.id.login_logo_img
                leftToRight = R.id.guideline_v_20
                rightToLeft = R.id.guideline_v_80
            }

            textView {
                text = "临床护理数据采集系统"
            }.lparams{
                setMargins(0,15,0,0)
                topToBottom = R.id.view_line
                rightToLeft = R.id.guideline_v_80
            }

            button{
                id=R.id.login_scan_bu
                setOnClickListener(clickListaner)
                setOnLongClickListener(longClickListaner)
                text="扫码进入"
            }.lparams(width = 0, height =dip(60)){
                topToBottom = R.id.guideline_h_70
                leftToRight = R.id.guideline_v_25
                rightToLeft = R.id.guideline_v_75
            }

            textView {
                text="北京子杰宝贝科技有限公司"
            }.lparams{
                setMargins(0,0,0,15)
                leftToLeft=PARENT_ID
                rightToRight=PARENT_ID
                bottomToBottom=PARENT_ID
            }
        }
    }
}